﻿
using Models.Common;
using Models.Device;

using UtilsBase;
using GatewayServerService.CloudCenter;

namespace GatewayServerService.Device
{
    /// <summary>
    /// //普锐森社-	风向传感器
    /// </summary>
    public class ServiceDeviceRS4851032_FX
    {

        //回调获获状态,为了避免误差，查状态和执行，都返回了 当前开关状态
        public void callBackUpdate(MQReqModel<object> httpReqModel)
        {
            try
            {
                ServiceCloudDeviceValueLog log = new ServiceCloudDeviceValueLog();
                ModelReceverData modelDeviceData = httpReqModel.toServerData;
                CommandLogModel commandLogModel = httpReqModel.toGatewayData;
                string result = modelDeviceData.commandResults[0].value;


                //0x01	0x03	0x04	0x00 0x02	0x00 0x5A	0xDB	0xC8
                string dataHex1 = result.Substring(9, 5);
                int direction = new UtilsDataTypeChange().hex16Convert10(dataHex1);
                string remark = "";
                if (direction == 0)
                {
                    remark = "北风";
                }
                else if (direction == 1)
                {
                    remark = "东北风";
                }
                else if (direction == 2)
                {
                    remark = "东风";
                }
                else if (direction == 3)
                {
                    remark = "东南风";
                }
                else if (direction == 4)
                {
                    remark = "南风";
                }
                else if (direction == 5)
                {
                    remark = "西南风";
                }
                else if (direction == 6)
                {
                    remark = "西风";
                }
                else if (direction == 7)
                {
                    remark = "西北";
                }
                log.writeSensorlog(commandLogModel.d_guid, "direction", direction.ToString(), "风向", remark);

                string dataHex2 = result.Substring(14, 5);
                int angle = new UtilsDataTypeChange().hex16Convert10(dataHex1);
                remark = "";
                if (angle == 0)
                {
                    remark = "北风";
                }
                else if (angle == 45)
                {
                    remark = "东北风";
                }
                else if (angle == 90)
                {
                    remark = "东风";
                }
                else if (angle == 135)
                {
                    remark = "东南风";
                }
                else if (angle == 180)
                {
                    remark = "南风";
                }
                else if (angle == 225)
                {
                    remark = "西南风";
                }
                else if (angle == 270)
                {
                    remark = "西风";
                }
                else if (angle == 315)
                {
                    remark = "西北";
                }
                log.writeSensorlog(commandLogModel.d_guid, "angle", angle.ToString(), "角度", remark);

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

    }

}
